/*
 * UAE - The Un*x Amiga Emulator
 *
 * Call (some) Amiga Exec functions outside the main UAE thread
 * and without stack magic.
 *
 * Copyright 1999 Patrick Ohly
 *
 * Uses the EXTER interrupt that is setup in filesys.c
 * and some of it needs thread support.
 */

#pragma once

#include "native2amiga_api.h"
#include "autoconf.h"
#include "traps.h"
#include "commpipe.h"

/*
 * The following functions are shortcuts for calling
 * the exec.library function with CallLib (), so they
 * are only available in a trap function. This trap
 * function has to be setup with deftrap2() and
 * TRAPFLAG_EXTRA_STACK and stack magic is required.
 */
uae_ptr uae_AllocMem(TrapContext* context, uint size, uint flags);
void uae_FreeMem(TrapContext* context, uae_ptr memory, uint size);

/*
 * to be called when setting up the hardware
 */
void native2amiga_install();

void native2amiga_reset();

/*
 * to be called when the Amiga boots, i.e. by filesys_diagentry()
 */
void native2amiga_startup();

/**** internal stuff ****/
#ifdef SUPPORT_THREADS
/* This pipe is filled by Signal() with pairs of
 * (uint)0/(uae_ptr)task/(uint)signal_set,
 * by PutMsg() with (uint)1/(uae_ptr)port/(uae_ptr)msg and by
 * ReplyMsg() with (uint)2/(uae_ptr)msg.
 * It's emptied via exter_int_helper by the EXTER interrupt. */
extern smp_comm_pipe native2amiga_pending;
#endif

void native2amiga_free();
static __forceinline void do_uae_int_requested()
{
    uae_int_requested |= 1;
    set_uae_int_flag();
}